home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / vendetta.c < prev    next >
C/C++ Source or Header  |  2000-03-18  |  3KB  |  127 lines

  1. #include "driver.h"
  2. #include "vidhrdw/konamiic.h"
  3.  
  4.  
  5. static int layer_colorbase[3],bg_colorbase,sprite_colorbase;
  6. static int layerpri[3];
  7.  
  8.  
  9. /***************************************************************************
  10.  
  11.   Callbacks for the K052109
  12.  
  13. ***************************************************************************/
  14.  
  15. static void tile_callback(int layer,int bank,int *code,int *color)
  16. {
  17.     *code |= ((*color & 0x03) << 8) | ((*color & 0x30) << 6) |
  18.             ((*color & 0x0c) << 10) | (bank << 14);
  19.     *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
  20. }
  21.  
  22.  
  23.  
  24. /***************************************************************************
  25.  
  26.   Callbacks for the K053247
  27.  
  28. ***************************************************************************/
  29.  
  30. static void sprite_callback(int *code,int *color,int *priority_mask)
  31. {
  32.     int pri = (*color & 0x03e0) >> 4;    /* ??????? */
  33.     if (pri <= layerpri[2])                                *priority_mask = 0;
  34.     else if (pri > layerpri[2] && pri <= layerpri[1])    *priority_mask = 0xf0;
  35.     else if (pri > layerpri[1] && pri <= layerpri[0])    *priority_mask = 0xf0|0xcc;
  36.     else                                                 *priority_mask = 0xf0|0xcc|0xaa;
  37.  
  38.     *color = sprite_colorbase + (*color & 0x001f);
  39. }
  40.  
  41.  
  42.  
  43. /***************************************************************************
  44.  
  45.     Start the video hardware emulation.
  46.  
  47. ***************************************************************************/
  48.  
  49. int vendetta_vh_start(void)
  50. {
  51.     if (K052109_vh_start(REGION_GFX1,NORMAL_PLANE_ORDER,tile_callback))
  52.         return 1;
  53.     if (K053247_vh_start(REGION_GFX2,NORMAL_PLANE_ORDER,sprite_callback))
  54.     {
  55.         K052109_vh_stop();
  56.         return 1;
  57.     }
  58.     return 0;
  59. }
  60.  
  61. void vendetta_vh_stop(void)
  62. {
  63.     K052109_vh_stop();
  64.     K053247_vh_stop();
  65. }
  66.  
  67.  
  68.  
  69. /***************************************************************************
  70.  
  71.   Display refresh
  72.  
  73. ***************************************************************************/
  74.  
  75. /* useful function to sort the three tile layers by priority order */
  76. static void sortlayers(int *layer,int *pri)
  77. {
  78. #define SWAP(a,b) \
  79.     if (pri[a] < pri[b]) \
  80.     { \
  81.         int t; \
  82.         t = pri[a]; pri[a] = pri[b]; pri[b] = t; \
  83.         t = layer[a]; layer[a] = layer[b]; layer[b] = t; \
  84.     }
  85.  
  86.     SWAP(0,1)
  87.     SWAP(0,2)
  88.     SWAP(1,2)
  89. }
  90.  
  91. void vendetta_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  92. {
  93.     int layer[3];
  94.  
  95.  
  96.     bg_colorbase       = K053251_get_palette_index(K053251_CI0);
  97.     sprite_colorbase   = K053251_get_palette_index(K053251_CI1);
  98.     layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
  99.     layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
  100.     layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
  101.  
  102.     K052109_tilemap_update();
  103.  
  104.     palette_init_used_colors();
  105.     K053247_mark_sprites_colors();
  106.     if (palette_recalc())
  107.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  108.  
  109.     tilemap_render(ALL_TILEMAPS);
  110.  
  111.     layer[0] = 0;
  112.     layerpri[0] = K053251_get_priority(K053251_CI2);
  113.     layer[1] = 1;
  114.     layerpri[1] = K053251_get_priority(K053251_CI3);
  115.     layer[2] = 2;
  116.     layerpri[2] = K053251_get_priority(K053251_CI4);
  117.  
  118.     sortlayers(layer,layerpri);
  119.  
  120.     fillbitmap(priority_bitmap,0,NULL);
  121.     K052109_tilemap_draw(bitmap,layer[0],TILEMAP_IGNORE_TRANSPARENCY|(1<<16));
  122.     K052109_tilemap_draw(bitmap,layer[1],2<<16);
  123.     K052109_tilemap_draw(bitmap,layer[2],4<<16);
  124.  
  125.     K053247_sprites_draw(bitmap);
  126. }
  127.